<template>
  <view class="statistics">
    <sta-item :type="type" :item="today"></sta-item>
    <sta-item title="本周" :type="type" :item="week"></sta-item>
    <sta-item title="本月" :type="type" :item="month"></sta-item>
    <sta-item title="上月" :type="type" :item="last_month"></sta-item>
  </view>
</template>

<script>
import { totalIncome, totalSales } from "@/utils/api";
// import StaItem from "./components/item";
export default {
  components: {
    // StaItem,
  },
  data() {
    return {
      type: "",
      today: {},
      week: {},
      month: {},
      last_month: {},
    };
  },
  onLoad({ type }) {
    this.type = Number(type);
    Number(type) ? this.initIncome() : this.initSales();
  },
  onReady() {
    var that = this;
    uni.setNavigationBarTitle({
      title: that.type ? "总收益" : "总销售额",
    });
  },
  methods: {
    initIncome() {
      totalIncome().then((resp) => {
        if (resp.code == 200) {
          const { name, team } = resp.data;
          // console.log("总收益", "name=", name, team);
          this.today = {
            mine: resp.data.name.today,
            team: resp.data.team.today,
          };
          this.week = {
            mine: resp.data.name.week,
            team: resp.data.team.week,
          };

          this.month = {
            mine: resp.data.name.month,
            team: resp.data.team.month,
          };

          this.last_month = {
            mine: resp.data.name.last_month,
            team: resp.data.team.last_month,
          };
        }
      });
    },
    initSales() {
      totalSales().then((resp) => {
        console.log(resp);
        if (resp.code == 200) {
          const { name, team } = resp.data;
          this.today = {
            mine: resp.data.name.money_today,
            team: resp.data.team.today,
          };
          this.week = {
            mine: resp.data.name.money_week,
            team: resp.data.team.week,
          };

          this.month = {
            mine: resp.data.name.money_month,
            team: resp.data.team.month,
          };

          this.last_month = {
            mine: resp.data.name.money_last_month,
            team: resp.data.team.last_month,
          };
        }
      });
    },
  },
};
</script>

<style lang="scss">
page {
  background-color: #f9f9f9;
}
.statistics {
  width: 100%;
  box-sizing: border-box;
  padding: 25rpx 30rpx 0 30rpx;
}
</style>
